#include "StdAfx.h"
#include "PNSearcher.h"

extern map<const unsigned long, FriendItem> gFriendList;
extern struct UserInfo gUserInfo;

PNSearcher::PNSearcher( const int SearchMask, const wstring Keyword ):m_FriendList(gFriendList)
{
	m_ResultList.clear();
	map<const unsigned long, FriendItem>::const_iterator c_iter;
	for (c_iter = m_FriendList.begin(); c_iter != m_FriendList.end(); c_iter++)
	{
		if (c_iter->first == _wtol(gUserInfo.m_UID.c_str()))
		{
			continue;
		}
		if (SearchMask & Need_Mask)
		{
			const list<NeedItem>& NeedList = c_iter->second.m_Needs;
			list<NeedItem>::const_iterator need_citer;
			for (need_citer = NeedList.begin(); need_citer != NeedList.end(); need_citer++)
			{
				if (wstring::npos != need_citer->m_Text.find(Keyword.c_str(), 0))
				{
					m_ResultList.push_back(*need_citer);
				}
				
			}
		}
		if (SearchMask & Provide_Mask)
		{
			const list<ProvideItem>& NeedList = c_iter->second.m_Provides;
			list<ProvideItem>::const_iterator provide_iter;
			for (provide_iter = NeedList.begin(); provide_iter != NeedList.end(); provide_iter++)
			{
				if (wstring::npos != provide_iter->m_Text.find(Keyword, 0))
				{
					m_ResultList.push_back(*provide_iter);
				}				
			}
		}
	}
}
PNSearcher::~PNSearcher(void)
{
}
